#include <stdio.h>    
#include <string.h>    
    
int translate(char num[], int x) {    
    int len = strlen(num);    
    int temp = 0, value = 1;    
    for (int i = len - 1; i >= 0; i--, value *= x) {    
        if (num[i] >= '0' && num[i] <= '9')    
            temp += value * (num[i] - '0');    
        else    
            temp += value * (num[i] - 'A' + 10);    
    }    
    return temp;    
}    
    
int main(void) {    
    char num1[105], num2[105], num1Max = 1, num2Max = 1;    
    if (scanf("%s%s", num1, num2)) ;    
    for (int i = 0; i < strlen(num1); i++) {    
        if (num1[i] >= '0' && num1[i] <= '9')    
            num1Max = num1Max > num1[i] - '0' ? num1Max : num1[i] - '0';    
        else    
            num1Max = num1Max > num1[i] - 'A' + 10 ? num1Max : num1[i] - 'A' + 10;    
    }    
    for (int i = 0; i < strlen(num2); i++) {    
        if (num2[i] >= '0' && num2[i] <= '9')    
            num2Max = num2Max > num2[i] - '0' ? num2Max : num2[i] - '0';    
        else    
            num2Max = num2Max > num2[i] - 'A' + 10 ? num2Max : num2[i] - 'A' + 10;    
    }    
    num1Max++;    
    num2Max++;    
    for (int i = num1Max; i <= 36; i++) {    
        int trueValue1 = translate(num1, i);    
        for (int j = num2Max; j <= 36; j++) {    
            int trueValue2 = translate(num2, j);    
            if (trueValue1 == trueValue2) {    
                printf("%s (base %d) = %s (base %d)\n", num1, i, num2, j);    
                return 0;    
            }    
        }    
    }    
    printf("%s is not equal to %s in any base 2..36\n", num1, num2);    
    return 0;    
}  